#ifndef __LIGHTBULB_BLOCK_H__
#define __LIGHTBULB_BLOCK_H__

#include "MountedElectricElementBlock.hpp"
#include "IPaintableBlock.hpp"

namespace PocketSurvival
{
    // 电灯
    class LightbulbBlock : public MountedElectricElementBlock, public IPaintableBlock
    {
    public:
        static constexpr int32_t Index()
        {
            return 139;
        }
        LightbulbBlock();
        virtual int32_t getIndex() override; 
        virtual const std::string &getBlockName() override;
        virtual int32_t getFace(int32_t value) override;

        virtual void getCreativeValues(std::vector<int32_t> &blockVec) override;
        virtual void getDropValues(int32_t oldValue, int32_t newValue, int32_t toolLevel, std::vector<BlockDropValue> &dropValues) override;
        
        virtual BlockPlacementData getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult) override;
        virtual const std::vector<BoundingBox> &getCustomCollisionBoxes(int32_t value) override;

        virtual int32_t getPaintColor(int32_t value) override;
        virtual int32_t paint(int32_t value, int32_t color) override;
        

        static inline int32_t GetMountingFace(int32_t data);
        static inline int32_t SetMountingFace(int32_t data, int32_t face);
        static inline int32_t GetLightIntensity(int32_t data);
        static inline int32_t SetLightIntensity(int32_t data, int32_t intensity);

        static inline int32_t GetColor(int32_t data);
        static inline int32_t SetColor(int32_t data, int32_t color);
		
    };

    inline int32_t LightbulbBlock::GetMountingFace(int32_t data)
    {
        return data & 7;
    }
    inline int32_t LightbulbBlock::SetMountingFace(int32_t data, int32_t face)
    {
        return (data & -8) | (face & 7);
    }
    inline int32_t LightbulbBlock::GetLightIntensity(int32_t data)
    {
        return (data >> 3) & 0xF;
    }
    inline int32_t LightbulbBlock::SetLightIntensity(int32_t data, int32_t intensity)
    {
        return (data & -121) | ((intensity & 0xF) << 3);
    }
    inline int32_t LightbulbBlock::GetColor(int32_t data)
    {
        if ((data & 0x80) != 0)
        {
        	return (data >> 8) & 0xF;
        }
        return -1;
    }
    inline int32_t LightbulbBlock::SetColor(int32_t data, int32_t color)
    {
		if (color != -1)
		{
			return (data & -3969) | 0x80 | ((color & 0xF) << 8);
		}
		return data & -3969;
    }
} // namespace PocketSurvival


#endif
